package swordoffer.offer57;

public class BinarySearch {
    public int[] twoSum(int[] nums, int target) {
        for (int i = 0; i < nums.length; ++i) {
            int l = i + 1;
            int r = nums.length - 1;
            int aim = target - nums[i];
            while (l < r) {
                int mid = l + (r - l) / 2;
                if (nums[mid] >= aim) {
                    r = mid;
                } else {
                    l = mid + 1;
                }
            }
            if (nums[l] == aim) {
                return new int[]{nums[i], nums[l]};
            }
        }
        return new int[0];
    }
}
